package com.tz.system.tag;

import java.util.List;

import com.tz.platform.tag.common.SelectCommonTag;
import com.tz.platform.utils.StringUtil;
import com.tz.system.cache.utils.ParameterPub;
import com.tz.system.menu.model.TSysMenu;

public class MenuSelectTag extends SelectCommonTag {
	private static final long serialVersionUID = 7743059246033485483L;

	@Override
	public String getSelectOption() {
		StringBuffer strOut = new StringBuffer();
		List<TSysMenu> menuList = ParameterPub.getAllMenus();
		if (getValue() == null || getValue().equals("")) {
			setValue("");
		}
		if (!StringUtil.msIsEmpty(getEmptyOptionName())) {
			strOut.append("<option value=\"\"> " + getEmptyOptionName() + " </option>");
		}

		for (TSysMenu menu : menuList) {
			if (menu.getMenuLevel() == 1) {
				if (getValue().equals(menu.getMenuCode())) {
					strOut.append("<option value=\"" + menu.getMenuCode() + "\" selected>" + menu.getMenuName() + "</option>");
				} else {
					strOut.append("<option value=\"" + menu.getMenuCode() + "\">" + menu.getMenuName() + "</option>");
				}
			}
		}

		return strOut.toString();
	}
}
